package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// MaterialFolder 素材表
type MaterialFolder struct {
	ID         string `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	MerchantID string `json:"merchant_id" gorm:"column:merchant_id;primaryKey;type:varchar(30);not null;default:'';comment:商户id"`
	Name       string `json:"name" gorm:"column:name;type:string;size:50;not null;default:'';comment:素材分组名称"`
	Type       int8   `json:"type" gorm:"column:type;type:tinyint(1);not null;default:1;comment:素材类型,1图片,2视频"`
	Sort       int8   `json:"sort" gorm:"column:sort;type:tinyint(1);not null;default:0;comment:排序"`
	PID        string `json:"pid" gorm:"column:pid;type:varchar(30);not null;default:'';comment:父级id"`
	CreatedAt  int64  `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	DeletedAt  int64  `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;not null;default:0;comment:删除时间"`
}

// TableName 表名
func (MaterialFolder) TableName() string {
	return "material_folder"
}

// BeforeCreate 自增id
func (l *MaterialFolder) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &MaterialFolder{})
}
